////////////////////////////////////////////////////////////////////////////
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
//  Copyright (c) Kentaro Sekimoto All rights reserved.
//
////////////////////////////////////////////////////////////////////////////

#include <tinyhal.h>
#include "..\..\..\DeviceCode\Targets\Native\RX62N\DeviceCode\iodefine.h"

//--//

#ifdef __cplusplus
extern "C" {
#endif
void BootstrapCode_Ext_SRAM(void)  __attribute__((section("SectionForBootstrapOperations")));
void BootstrapCode_Board(void)  __attribute__((section("SectionForBootstrapOperations")));
#ifdef __cplusplus
}
#endif

#if 0
void SRAM_WKLCD62N(void) __attribute__ ((section ("SectionForBootstrapOperations")));
void SRAM_WKLCD62N(void)
{
	SYSTEM.SCKCR.LONG = 0x00010100;	// ICLK=96MHz,BCLK=48MHz,PCLK=48MHz
	IOPORT.PF0CSE.BIT.CS4E = 1;
	IOPORT.PF1CSS.BIT.CS4S = 0;
	IOPORT.PF3BUS.BYTE = 0x1f;
	IOPORT.PF4BUS.BYTE = 0xff;
	IOPORT.PF5BUS.BYTE = 0x52;
	IOPORT.PF6BUS.BYTE = 0x00;
	BSC.CS4MOD.WORD = 0x8001;
	BSC.CS4CR.WORD = 0x0001;
	SYSTEM.SYSCR0.WORD = 0x5a03;
	BSC.CS4WCR1.LONG = 0x04040000;
	BSC.CS4WCR2.LONG = 0x00110111;
	BSC.CS4REC.WORD = 0x0000;
}
#endif

void BootstrapCode_Ext_SRAM(void) __attribute__ ((section ("SectionForBootstrapOperations")));
void BootstrapCode_Ext_SRAM(void)
{
	SYSTEM.SYSCR0.WORD = 0x5a03;
	IOPORT.PF0CSE.BYTE = 0x18;
	IOPORT.PF1CSS.BYTE = 0x00;
	IOPORT.PF2CSS.BYTE = 0x00;
	IOPORT.PF3BUS.BYTE = 0x17;
	IOPORT.PF4BUS.BYTE = 0xff;
	IOPORT.PF5BUS.BYTE = 0x52;
	BSC.CS3CR.WORD = 0x0001;
	BSC.CS3MOD.WORD = 0x8001;
	BSC.CS3WCR1.LONG = 0x07070707;
	BSC.CS3WCR2.LONG = 0x11110111;
	BSC.CS3REC.WORD = 0x0000;
	BSC.CS4CR.WORD = 0x0001;
	BSC.CS4MOD.WORD = 0x8001;
	BSC.CS4WCR1.LONG = 0x07070707;
	BSC.CS4WCR2.LONG = 0x11110111;
	BSC.CS4REC.WORD = 0x0000;
}

void BootstrapCode_Board(void) __attribute__ ((section ("SectionForBootstrapOperations")));
void BootstrapCode_Board(void)
{
	BootstrapCode_Ext_SRAM();
}

